<style>
.confirm-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 9999;
}

.confirm-content {
  width: 7rem;
  background: rgba(22, 24, 35, 0.98);
  border-radius: 0.2rem;
  padding-top: .5333rem;
  text-align: center;
}

.confirm-title {
  margin-bottom: .2667rem;
  font-size: .48rem;
  font-weight: bold;
  color: rgba(255, 255, 255, 0.5);
}

.confirm-desc {
  font-size: .4267rem;
  margin-bottom: .5333rem;
  color: #666;
}

.confirm-buttons {
  width: 7rem;
  display: flex;
  justify-content: space-around;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.confirm-buttons button {
  width: 3.5rem;
  height: 1.3rem;
  border: none;
  border-radius: .1333rem;
  cursor: pointer;
  background-color: transparent;
}

.confirm-buttons button:first-child {
  border-right: 1px solid rgba(255, 255, 255, 0.1);
  color: #fff;
}

.confirm-buttons button:last-child {
  color: #fff;
}

::deep(.confirm-fade-enter-active) {
  animation: confirmFadeIn 0.5s ease-in-out;
}

::deep(.confirm-fade-leave-active) {
  animation: confirmFadeOut 0.5s ease-in-out;
}

@keyframes confirmFadeIn {
  from {
    opacity: 0;
    transform: scale(0);
  }

  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes confirmFadeOut {
  from {
    opacity: 1;
    transform: scale(1);
  }

  to {
    opacity: 0;
    transform: scale(0);
  }
}
</style>
<template>
  <transition name="confirm-fade">
    <teleport to="body">
      <div class="confirm-modal" v-if="visible">
        <div class="confirm-content">
          <h3 class="confirm-title">{{ title }}</h3>
          <p class="confirm-desc">{{ content }}</p>
          <div class="confirm-buttons">
            <button @click="handleCancel">取消</button>
            <button @click="handleConfirm">确定</button>
          </div>
        </div>
      </div>
    </teleport>
  </transition>
</template>

<script setup>
import { ref, defineProps, defineEmits } from 'vue';

const props = defineProps({
  title: { type: String, default: '确认操作' },
  content: { type: String, default: '是否确认执行该操作？' },
  visible: { type: Boolean, default: false }
});

const emit = defineEmits(['cancel', 'confirm']);

const handleCancel = () => {
  emit('cancel');
};

const handleConfirm = () => {
  emit('confirm');
};
</script>